package com.design;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 反射破坏单列模式
 */
public class ReflectTest {

    public static void main(String[] args) {
        Class<?> clazz = LazyStaticInnerClassSingleton.class;

        try {
            Constructor<?> constructor = clazz.getDeclaredConstructor(null);
            constructor.setAccessible(true);
            Object instance1 = constructor.newInstance();
            Object instance2 = constructor.newInstance();
            System.out.println(instance1);
            System.out.println(instance2);
            System.out.println(instance1.equals(instance2));
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }


//        String s1 = "ab";
//        String s2 = "abc";
//        String s3 = s1 + "c";
//        System.out.println(s2 == s3);
//        System.out.println(s2.equals(s3));

    }
}
